package fr.tvbarthel.games.chasewhisply.model.bestiary;


import java.util.ArrayList;
import java.util.List;

import fr.tvbarthel.games.chasewhisply.R;
import fr.tvbarthel.games.chasewhisply.model.DisplayableItemFactory;

public class BestiaryEntryFactory {

    public static class StageEntry{

        public StageEntry(int ghost_default,int ghost_type_0, int ghost_type_1)
        {
            this.ghost_default = ghost_default;
            this.ghost_type_0 = ghost_type_0;
            this.ghost_type_1 = ghost_type_1;
            this.ghost_type_2 = ghost_type_0;
            this.ghost_type_3 = ghost_type_1;
        }

        public  int ghost_type_0;
        public  int ghost_type_1;
        public  int ghost_type_2;
        public  int ghost_type_3;
        public  int ghost_default;

    }

    public static class StageEntryManager{
        private static List<StageEntry> mStages = new ArrayList<>() ;
        private static int mStagesIndex = 0;

        static {
            mStages.add(new StageEntry(R.drawable.bat_night,R.drawable.batnight1,R.drawable.batnight2));
            mStages.add(new StageEntry(R.drawable.bat_night,R.drawable.batnight3,R.drawable.batnight4));
            mStages.add(new StageEntry(R.drawable.bat_night,R.drawable.batnight5,R.drawable.batnight6));
            mStages.add(new StageEntry(R.drawable.bat_night,R.drawable.batnight7,R.drawable.batnight8));
        }

        public  static void addStages() {
            mStagesIndex ++;
        }

        public  static void decreaStages() {
            mStagesIndex --;
            if (mStagesIndex <=0) mStagesIndex=0;
        }

        public  static StageEntry getStage(int index)
        {
            index = index % mStages.size();
            return  mStages.get(index);
        }

        public  static StageEntry getStage()
        {
            int index = mStagesIndex % mStages.size();
            return  mStages.get(index);
        }
    }



    public static BestiaryEntry createBestiaryEntry(int ghostType) {
        BestiaryEntry bestiaryEntry = new BestiaryEntry();

        StageEntry currentStage = StageEntryManager.getStage();

        switch (ghostType) {
            case DisplayableItemFactory.TYPE_GHOST_WITH_HELMET:
                bestiaryEntry.setTargetableItem(DisplayableItemFactory.createGhostWithHelmet());
                bestiaryEntry.setImageResourceId(R.drawable.ghost_with_helmet_5);
                bestiaryEntry.setTitleResourceId(R.string.bestiary_ghost_with_helmet_title);

                //modify by dabao
                bestiaryEntry.setImageResourceId(currentStage.ghost_type_0);

                break;
            case DisplayableItemFactory.TYPE_BABY_GHOST:
                bestiaryEntry.setTargetableItem(DisplayableItemFactory.createBabyGhost());
                bestiaryEntry.setImageResourceId(R.drawable.baby_ghost);
                bestiaryEntry.setTitleResourceId(R.string.bestiary_baby_ghost_title);


                //modify by dabao
                bestiaryEntry.setImageResourceId(currentStage.ghost_type_1);
                break;

            case DisplayableItemFactory.TYPE_HIDDEN_GHOST:
                bestiaryEntry.setTargetableItem(DisplayableItemFactory.createHiddenGhost());
                bestiaryEntry.setImageResourceId(R.drawable.hidden_ghost);
                bestiaryEntry.setTitleResourceId(R.string.bestiary_hidden_ghost_title);

                //modify by dabao
                bestiaryEntry.setImageResourceId(currentStage.ghost_type_2);
                break;

            case DisplayableItemFactory.TYPE_KING_GHOST:
                bestiaryEntry.setTargetableItem(DisplayableItemFactory.createKingGhost());
                bestiaryEntry.setImageResourceId(R.drawable.king_ghost);
                bestiaryEntry.setTitleResourceId(R.string.bestiary_king_ghost_title);

                //modify by dabao
                bestiaryEntry.setImageResourceId(currentStage.ghost_type_3);
                break;

            case DisplayableItemFactory.TYPE_BLOND_GHOST:
                bestiaryEntry.setTargetableItem(DisplayableItemFactory.createBlondGhost());
                bestiaryEntry.setImageResourceId(R.drawable.blond_ghost_in_tears);
                bestiaryEntry.setTitleResourceId(R.string.bestiary_blond_ghost_title);

                //modify by dabao
                bestiaryEntry.setImageResourceId(currentStage.ghost_default);
                break;

            default:
                bestiaryEntry.setTargetableItem(DisplayableItemFactory.createEasyGhost());
                bestiaryEntry.setImageResourceId(R.drawable.ghost);
                bestiaryEntry.setTitleResourceId(R.string.bestiary_easy_ghost_title);
                //modify by dabao
                bestiaryEntry.setImageResourceId(currentStage.ghost_default);
                break;
        }
        return bestiaryEntry;
    }
}
